﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Helpers.Converters
{
    public class BoolToToggleValue : DependencyObject, IValueConverter
    {
        #region Properties

        #region FalseValue
        public string FalseValue
        {
            get { return (string)GetValue(FalseValueProperty); }
            set { SetValue(FalseValueProperty, value); }
        }
        public static readonly DependencyProperty FalseValueProperty = DependencyProperty.Register(
            "FalseValue",
            typeof(string),
            typeof(BoolToToggleValue),
            new UIPropertyMetadata("False"));
        #endregion
        #region TrueValue
        public string TrueValue
        {
            get { return (string)GetValue(TrueValueProperty); }
            set { SetValue(TrueValueProperty, value); }
        }
        public static readonly DependencyProperty TrueValueProperty = DependencyProperty.Register(
            "TrueValue", 
            typeof(object), 
            typeof(BoolToToggleValue), 
            new UIPropertyMetadata("True"));
        #endregion

        #endregion

        #region Methods

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((value != null) && (value.Equals(true) == true))
                       ? this.TrueValue
                       : this.FalseValue;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter.Equals(this.TrueValue) == true)
                return true;
            else if (parameter.Equals(this.FalseValue) == true)
                return false;
            else
                return DependencyProperty.UnsetValue;
        }

        #endregion
    }
}
